package com.dalin.platform.loa;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import com.dalin.common.utils.StringUtils;
import com.dalin.platform.loa.vo.WsCurrentUserInfo;
import com.dalin.platform.loa.vo.WsDicItemVo;

/*****************************************************************************
 * @content: loa工程静态属性及类方法                                                                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2009-07-27                                                     *
 ****************************************************************************/
public final class LoaConst {
	private LoaConst() {}
	// 密码初始化
	public static final String INITIALIZATION_PSWD = "123456";
	// 系统中所有可用字典表
	private static final Map<String, List<WsDicItemVo>> dicListMap = new HashMap<String, List<WsDicItemVo>>();
	
	
	// 系统所有字典表类型
	public static final String[] DIC_TYPE_CODE_ARRAY = {
		"databaseDriver", "databaseType", "nullable", "usable", "visible",
		 "displayWay", "valid", "sex", "resourceType"};
	
	// 树型目录或递归调用时父根ID值
	public static final Integer BASE_PARENT_ID = -999;
	
	// 验证码
	public static final String RANDOM_AUTHENTICODE_SESSION_NAME = "randomAuthenticode";
	public static final int RANDOM_AUTHENTICODE_EXPIRE = 60;
	
	/* 用户角色授权情况显示 */
	public static final String IS_AUTHORIZED = "已授权";
	public static final String NOT_AUTHORIZED = "未授权";
	
	// 超级管理员
	public static final String THIS_ADMINISTRATOR_NAME = "njl";
	public static final String THIS_ADMINISTRATOR_PSWD = "najianlin123";
	
	// cookie过期时间
	public static final int COOKIE_EXPIRE = Integer.MAX_VALUE;
	
	//根据键值查找上传文件fileInfo.properties相应的参数
	public final static String getFileInfoParam(String key) {
		ResourceBundle rb = ResourceBundle.getBundle("fileInfo");
		return rb.getString(key);
	}
	
	// 存储登录用户信息
	private static final Map<Long, WsCurrentUserInfo> currentUserInfoMap = 
		new HashMap<Long, WsCurrentUserInfo>();
	public static void cacheLoginedUserInfo(WsCurrentUserInfo cui) {
		currentUserInfoMap.put(cui.getLum(), cui);
	}
	
	
	
	//取得登录过的用户
	public static WsCurrentUserInfo getLoginedUserInfoByLum(Long lum) {
		return currentUserInfoMap.get(lum);
	}
	
	
	
	
	
	public static final String getUserNameById(Long userId) {
		return "无此用户";
	}
	
	
	// 转换为名称
	public static final String findItemName(String typeCode, String itemCode) {
		if (StringUtils.isBlank(itemCode)) return "";
		String rtnStr = "请选择...";
		List<WsDicItemVo> dataList = dicListMap.get(typeCode);
		for (WsDicItemVo vo : dataList) {
			if (vo.getItemCode().equals(itemCode)) {
				rtnStr = vo.getItemName();
				break;
			}
		}
		return rtnStr;
	}
	// 转换为代码
	public static final String findItemCode(String tc, String itemName) {
		if (StringUtils.isBlank(itemName)) return "";
		String rtnCode = null;
		List<WsDicItemVo> dataList = dicListMap.get(tc);
		for (WsDicItemVo vo : dataList) {
			if (vo.getItemName().equals(itemName)) {
				rtnCode = vo.getItemCode();
				break;
			}
		}
		return rtnCode;
	}
}